

<!--        文件上传 from的enctype必须使用：multipart/form-data-->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.4</version>
        </dependency>
<!--        文件下载-->
        <dependency>
            <groupId>commons-io</groupId>
            <artifactId>commons-io</artifactId>
            <version>2.6</version>
        </dependency>

        


@YWebPath("/upimage")
    public RetType upImage(HttpServletRequest req){
        //创建工厂实现类
        FileItemFactory fileItemFactory=new DiskFileItemFactory();
        ServletFileUpload servletFileUpload =new ServletFileUpload(fileItemFactory);
        try {
            //解析上传的信息
            List<FileItem> list = servletFileUpload.parseRequest(req);
            //遍历上传的信息--解析表单内的内容
            for (FileItem fileItem : list) {
                if (!fileItem.isFormField())  {   //文件信息
                    System.out.println("文件 表单属性" + fileItem.getFieldName());
                    System.out.println("上传的文件名:" + fileItem.getName());
                    byte[] bytes = fileItem.get();
                    //做文件数据库保存
                }
            }
        }catch (Exception e) {
            e.printStackTrace();
        }
        return RetType.retJson("ok");
    }

    @YWebPath("/downimage")
    public RetType downImage(String imgName, HttpServletResponse resp) throws Exception {

        byte [] img = new byte[0];
        String filename = null;
        //读数据库

        resp.setHeader("Content-Disposition", "attachment;filename=" + URLEncoder.encode(filename, "UTF-8"));
        ByteArrayInputStream stream = new ByteArrayInputStream(img);
        ServletOutputStream outputStream = resp.getOutputStream();
        //实现浏览器下下载功能
        IOUtils.copy(stream, outputStream);
        return RetType.retEmpty();
    }

